package com.tanhua.db.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.api.UserApi;
import com.tanhua.db.mapper.UserMapper;
import com.tanhua.model.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Wrapper;
import java.util.List;

@DubboService
public class UserApiImpl implements UserApi {
    @Autowired
    private UserMapper userMapper;

    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getMobile, mobile);
        User user = userMapper.selectOne(wrapper);
        return user;

    }

    public Long save(User user){
       userMapper.insert(user);
       return user.getId();
    }

    @Override
    public void updateById(User user) {
        userMapper.updateById(user);
    }

    @Override
    public List<User> findAll() {
        List<User> userList = userMapper.selectList(null);
        return userList;
    }

    @Override
    public User findById(Long getid) {
        User user = userMapper.selectById(getid);
        return user;
    }

    @Override
    public User findByhuanxinId(String huanxinId) {
        User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getHxUser, huanxinId));
        return user;
    }


}
